# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
from selenium.webdriver.support import expected_conditions as EC # available since 2.26.0
from selenium.webdriver.common.action_chains import ActionChains
import unittest
import random
import time
from cookies import lasthopes, randomword
import re
import string
import sys
from selenium.webdriver.common.keys import Keys
from PIL import Image
from os import remove, listdir, sep
from os.path import basename, isfile
import tempfile
from warnings import warn
from baseclass import BaseClass

class backcall_ok_dbl(BaseClass):
    def test_backcall_ok_dbl(self):
        randnumber = str(random.randrange(1000000000, 9999999999))
        test_texts = (u'Заявка на обратный звонок принята',\
                      u'Время ожидания может составить более',\
                      u'Оператор свяжется с Вами в течение', u'Точно не робот',\
                      u'Ваш запрос на обратный звонок уже в очереди',\
                      u'Оператор свяжется с Вами в течение',)
        driver = self.driver
        #Link to callback
        inputElement = driver.find_element_by_css_selector("div.b-header-top-contacts-offline-callback")\
                       .find_element_by_css_selector("span.g-pseudo-h")
        inputElement.click()
        #Callback popup
        call_pop = self.wait_for_popub_name(u'Обратный звонок')
        #Send valid number
        inp_phone = call_pop.find_element_by_name("phone")
        inp_phone.clear()
        inp_phone.click()
        inp_phone.send_keys(randnumber)
        send_btn = call_pop.find_element_by_css_selector("input.b-sbutton-input")
        send_btn.click()
        #Check for ok popup
        call_pop = self.wait_pop_with_any_text(test_texts)
        call_pop.find_element_by_css_selector("div.b-popup-close").click()
        #Check popup disappears
        WebDriverWait(driver, timeout=20).until(lambda dr: not self.check_exists(call_pop))
